<!--倒冲记录-->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
      </template>
      <template slot-scope="{ row }" slot="menu">
        <el-button
          type="text"
          icon="el-icon-view"
          size="small"
          plain
          style="border: 0; background-color: transparent !important"
          v-if="permission.backWashRecord_view"
          @click.stop="handleView(row)"
          >详情
        </el-button>
      </template>
    </avue-crud>
    <el-dialog custom-class="packBoxDialog" append-to-body :close-on-click-modal="false" title="倒冲详情" :visible.sync="showDialog" v-if="showDialog" width="60%" top="7vh">
      <avue-crud
        :page.sync="detailPage"
        :option="sheetOption"
        :table-loading="detailLoading"
        :data="sheetData"
        v-model="sheetForm"
        @current-change="currentDetailChange"
        @size-change="sizeDetailChange"
        @on-load="getListData"
      >
        <template slot-scope="{ row }" slot="menu">
          <el-button type="text" icon="el-icon-view" size="small" plain style="border: 0; background-color: transparent !important" @click.stop="handlePackView(row)"
            >包装详情
          </el-button>
        </template>
      </avue-crud>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <el-dialog
      custom-class="packBoxDialog pack-dialog"
      append-to-body
      :close-on-click-modal="false"
      title="包装详情"
      :visible.sync="packDialog"
      v-if="packDialog"
      width="55%"
      top="7vh"
    >
      <div class="partInfo">
        <div style="width: 50%; margin-bottom: 10px">物料编码：{{ partObj.partNo }}</div>
        <div style="width: 50%; margin-bottom: 10px">物料名称：{{ partObj.partName }}</div>
        <div style="width: 50%; margin-bottom: 10px">物料规格：{{ partObj.partModel }}</div>
      </div>
      <avue-crud
        :option="packOption"
        :table-loading="packLoading"
        :data="packData"
        :page.sync="packPage"
        @current-change="currentPackDetailChange"
        @size-change="sizePackDetailChange"
        v-model="packForm"
        @on-load="getPackListData"
      >
      </avue-crud>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="packDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <export-comp ref="exportComp" page-api-url="mes-abacus/back-flush/page-query" :option="option" :page="page" :query="query" file-name="倒冲记录"> </export-comp>
  </basic-container>
</template>

<script>
import { getList, getDetail, getPackDetail } from '@/api/warehouse/backWashRecord';
import exportComp from '@/components/export-comp';
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';

export default {
  components: {
    exportComp,
    userTableConfig
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'BACKWASHRECORD',
      form: {},
      query: {},
      sheetForm: {},
      packForm: {},
      partObj: {},
      properties: {},
      loading: false,
      detailLoading: false,
      packLoading: false,
      tableOption: [], //模态框配置
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      detailPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      packPage: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      showDialog: false,
      packDialog: false,
      data: [],
      sheetData: [],
      packData: [],
      option: {
        calcHeight: 30,
        height: 'calc(100vh - 440px)',
        tip: false,
        searchShow: true,
        searchMenuPosition: 'right',
        searchMenuSpan: 4,
        dialogClickModal: false,
        searchLabelWidth: 120,
        border: true,
        viewBtn: false,
        addBtn: false,
        selection: true,
        printBtn: false,
        editBtn: false,
        delBtn: false,
        index: false,
        searchSpan: 5,
        columnBtn: false,
        menuWidth: 100,
        column: [
          {
            label: '倒冲单号',
            prop: 'backFlushSheetNo',
            search: true
          },
          // {
          //   label: '倒冲时机',
          //   prop: 'backflushChance',
          //   type: 'select',
          //   dicUrl: '/api/blade-system/dict/dictionary?code=backflush_chance',
          //   props: {
          //     label: 'dictValue',
          //     value: 'dictKey'
          //   }
          // },
          // {
          //   label: '关联领料单号',
          //   prop: 'backFlushRo',
          //   search: true
          // },
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true
          },
          {
            label: '生产订单',
            prop: 'productionOrderNo'
          },
          {
            label: '产品编码',
            prop: 'partNo',
            search: true
          },
          {
            label: '产品名称',
            prop: 'partName'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            search: true,
            dicData: [
              { label: '已发料', value: 0 },
              { label: '待备料', value: 1 },
              { label: '欠料待倒冲', value: 2 },
              { label: '备料中', value: 3 },
              { label: '待拣货', value: 4 },
              { label: '拣货中', value: 5 },
              { label: '已拣货', value: 6 }
            ]
          },
          {
            label: '倒冲时间',
            prop: 'backFlushTime'
          }
        ]
      },
      sheetOption: {
        tip: false,
        searchShow: false,
        dialogClickModal: false,
        height: '400',
        border: true,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        cancelBtn: false,
        saveBtn: false,
        selection: false,
        menu: false,
        page: true,
        index: true,
        indexLabel: '序号',
        refreshBtn: false,
        expandBtn: false,
        columnBtn: false,
        menuWidth: 120,
        column: [
          {
            label: '物料名称',
            prop: 'partName'
          },
          {
            label: '物料编码',
            prop: 'partNo',
            type: 'search'
          },
          {
            label: '物料规格',
            prop: 'partModel',
            type: 'search'
          },
          {
            label: '倒冲时机',
            prop: 'backflushChance',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=backflush_chance',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '需求数量',
            prop: 'quantity'
          },
          {
            label: '倒冲数量',
            prop: 'backFlushQuantity'
          },
          {
            label: '物料批次',
            prop: 'lotNo'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            search: true,
            dicData: [
              { label: '已发料', value: 0 },
              { label: '待备料', value: 1 },
              { label: '欠料待倒冲', value: 2 },
              { label: '备料中', value: 3 },
              { label: '待拣货', value: 4 },
              { label: '拣货中', value: 5 },
              { label: '已拣货', value: 6 }
            ]
          }
          // {
          //   label: '仓库',
          //   prop: 'inventoryName'
          // }
          // {
          //   label: '储位',
          //   prop: 'areaName'
          // }
        ]
      },
      packOption: {
        tip: false,
        searchShow: false,
        dialogClickModal: false,
        height: '400',
        border: true,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        cancelBtn: false,
        saveBtn: false,
        selection: false,
        menu: false,
        page: true,
        index: true,
        indexLabel: '序号',
        refreshBtn: false,
        expandBtn: false,
        columnBtn: false,
        menuWidth: 120,
        column: [
          {
            label: '包装条码',
            prop: 'packBarCode'
          },
          {
            label: '包装数量',
            prop: 'packQuantity'
          },
          {
            label: '物料批次',
            prop: 'lotNo'
          },
          {
            label: '仓库',
            prop: 'inventoryName'
          },
          {
            label: '储位',
            prop: 'areaName'
          },
          {
            label: '状态',
            prop: 'packStatus',
            width: 100,
            type: 'select',
            dicData: [
              { label: '正常', value: 1 },
              { label: '全部锁定', value: 2 },
              { label: '部分锁定', value: 3 },
              { label: '报废', value: 4 },
              { label: '已出库', value: 5 },
              { label: '已入库', value: 6 },
              { label: '待检锁定', value: 7 },
              { label: '逾期锁定', value: 8 },
              { label: '待报废', value: 9 },
              { label: '作废', value: 10 },
              { label: '已上架', value: 11 }
            ]
          }
        ]
      }
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.backWashRecord_view, false)
      };
    }
  },
  methods: {
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    sizeDetailChange(pageSize) {
      this.detailPage.pageSize = pageSize;
    },
    currentDetailChange(currentPage) {
      this.detailPage.currentPage = currentPage;
    },
    sizePackDetailChange(pageSize) {
      this.packPage.pageSize = pageSize;
    },
    currentPackDetailChange(currentPage) {
      this.packPage.currentPage = currentPage;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    /**
     * 查看模态框
     */
    handleView(row) {
      this.detailPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      this.sheetForm.backFlushSheetId = row.backFlushSheetId;
      this.showDialog = true;
    },
    /*
     * 查看包装模态框
     */
    handlePackView(row) {
      this.packPage = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      this.packForm.backFlushSheetId = this.sheetForm.backFlushSheetId;
      this.packForm.backFlushSheetDetailId = row.backFlushSheetDetailId;
      this.partObj.partNo = row.partNo;
      this.partObj.partName = row.partName;
      this.partObj.partModel = row.partModel;
      this.packDialog = true;
    },
    /**
     * 获取单据详情
     */
    getListData(page, params = {}) {
      this.detailLoading = true;
      getDetail(page.currentPage, page.pageSize, Object.assign(params, this.sheetForm)).then((res) => {
        const data = res.data.data;
        this.sheetData = data.records;
        this.detailPage.total = data.total;
        this.detailLoading = false;
      });
    },
    /**
     * 获取包装详情
     */
    getPackListData(page, params = {}) {
      this.packLoading = true;
      getPackDetail(page.currentPage, page.pageSize, Object.assign(params, this.packForm)).then((res) => {
        const data = res.data.data;
        this.packData = data.records;
        this.packPage.total = data.total;
        this.packLoading = false;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .packBoxDialog {
  .avue-crud__menu {
    display: none;
  }
}
::v-deep .pack-dialog .el-dialog__body {
  padding: 10px 20px;
}
.partInfo {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
</style>
